<template>
	<view>
		<u-form>
			<u-form-item prop="username" :leftIconStyle="{color: '#888', fontSize: '32rpx'}" left-icon="account" label-width="200"
			 :label-position="labelPosition" label="用户名">
				<u-input v-model="user.username" />
			</u-form-item>
			<u-form-item :label-position="labelPosition" label="密码">
				<u-input v-model="user.password" />
			</u-form-item>
			<button @click="login()">登录</button>
		</u-form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					username: "admin01",
					password: "admin01"
				},
				labelPosition: "left"
			}
		},
		methods: {
			async login() {
				const res = await this.$myRequest({
					url: '/doLogin',
					method: 'post',
					data: this.user,
					
				})
				if (res.data.error) {
					return uni.showToast({
						title: res.data.error,
						icon: "none"
					})
				}
				console.log(res.data)
				//同步存储token
				uni.setStorageSync('token', res.data.data.token);
				uni.setStorageSync('id', res.data.data.id)
				uni.setStorageSync("username", res.data.data.username)
				uni.redirectTo({
					url:"../function/function"
				})
			}
		}
	}
</script>

<style>

</style>
